package com.kl.forum.service;

import com.kl.forum.dao.ColumnDicMapper;
import com.kl.forum.dao.RelUserColumnMapper;
import com.kl.forum.entity.ColumnDic;
import com.kl.forum.entity.RelUserColumn;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ColumnDicService {
    @Autowired
    private ColumnDicMapper columnDicMapper;

    @Autowired
    private RelUserColumnMapper relUserColumnMapper;

    /**
     *获取所有菜单
     * @return
     */
    public List<Map> getAllColumn(){
       return columnDicMapper.getAllColumn();
    }

    /**
     * 获取用户栏目关联
     * @param userId
     * @return
     */
    public  RelUserColumn getUserColumnByUserId(Integer userId){
        Map<String,Object> map =new HashMap<>();
        map.put("userId",userId);
        return   relUserColumnMapper.getUserColumnByUserId(map);
    }

    public  int  insert(Integer userId,String data){
        RelUserColumn relUserColumn=new RelUserColumn();
        relUserColumn.setCreateTime(new Date());
        relUserColumn.setColumnData(data);
        relUserColumn.setUserId(userId);
        return  relUserColumnMapper.insertSelective(relUserColumn);
    }

    public  int update(Integer userId ,String columnData,String columnDataHide,Integer id){
        RelUserColumn relUserColumn=new RelUserColumn();
        relUserColumn.setColumnData(columnData);
        relUserColumn.setColumnDataHide(columnDataHide);
        relUserColumn.setUserId(userId);
        relUserColumn.setId(id);
        return  relUserColumnMapper.updateByPrimaryKeySelective(relUserColumn);
    }

}
